FROM golang:latest AS builder

RUN mkdir /app
ADD . /app
WORKDIR /app
ENV GOPROXY=https://goproxy.cn,direct
RUN go mod tidy && \
    CGO_ENABLED=0 GOOS=linux go build -o app .


FROM alpine:latest AS production
RUN mkdir /app
WORKDIR /app
ENV ENV=docker
COPY --from=builder /app/config ./config
COPY --from=builder /app/env/$ENV.json ./env/$ENV.json
COPY --from=builder /app/app .

EXPOSE 8090

CMD ["./app", "init-db"]

#docker build -t app:v1.0 .

#docker run --name mysql --env=MYSQL_ROOT_PASSWORD=123 --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=GOSU_VERSION=1.16 --env=MYSQL_MAJOR=8.0 --env=MYSQL_VERSION=8.0.33-1.el8 --env=MYSQL_SHELL_VERSION=8.0.33-1.el8  --network my-network -v /Users/tuyuanhui/docker/data/mysql:/var/lib/mysql -p 3307:3306 --restart=no --runtime=runc -d mysql

#docker run --name redis --network my-network --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=GOSU_VERSION=1.16 --env=REDIS_VERSION=7.0.11 --env=REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-7.0.11.tar.gz --env=REDIS_DOWNLOAD_SHA=ce250d1fba042c613de38a15d40889b78f7cb6d5461a27e35017ba39b07221e3 -v /Users/tuyuanhui/docker/data/redis:/data --workdir=/data -p 63790:6379 --restart=no --runtime=runc -d redis

#docker run --name go_app --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=ENV=docker --network=my-network --workdir=/app -p 8090:8090 --runtime=runc -t -d app